package com.example.myzhugezhaofang.adapter;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.mvplibrary.adapter.BaseAdapter;
import com.example.mvplibrary.adapter.BaseViewHolder;
import com.example.myzhugezhaofang.R;
import com.example.myzhugezhaofang.bean.NewHotsBean;

import java.util.List;

public class NewsHotsAdapter extends BaseAdapter<NewHotsBean.ListBean> {
    public onItemListener itemListener;

    public void setListener(onItemListener listener) {
        this.itemListener = listener;
    }

    public NewsHotsAdapter(List<NewHotsBean.ListBean> datas, Context context, int layoutId) {
        super(datas, context, layoutId);
    }

    @Override
    protected void bindData(BaseViewHolder holder, NewHotsBean.ListBean listBean, int position) {
        TextView text1 = holder.getView(R.id.tv_item_newsHots_1);
        TextView text2 = holder.getView(R.id.tv_item_newsHots_2);
        ImageView image = holder.getView(R.id.iv_item_newsHots);
        text1.setText(listBean.getTitle());
        text2.setText(listBean.getC_name());
        Glide.with(context).load(listBean.getThumb()).into(image);

        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                itemListener.onClick(position);
            }
        });
    }

    interface onItemListener {
        void onClick(int n);
    }
}
